<?php
error_reporting(E_ALL);
include_once $_SERVER['DOCUMENT_ROOT']."/resources/Classes/access_user/access_user_class.php";

$username = "";
if (array_key_exists("username", $_POST))
{
        $username = $_POST['username'];
}

$password = "";
if (array_key_exists("password", $_POST))
{
        $password = $_POST['password'];
}

$fn = "";
if (array_key_exists("fn", $_POST))
{
        $fn = $_POST['fn'];
}

switch ($fn)
{
	case 'login':

	
		$my_access = new Access_user();
		$my_access->save_login = "no"; // use a cookie to remember the login
		$my_access->count_visit = true; // if this is true then the last visitdate is saved in the database (field extra info)
		$my_access->access_page();
		
		$my_access->login_user($username, $password); // call the login method
		
		$my_access->get_user_info();
		
		if ($my_access->the_msg != '')
		{
			$toJson[0]->Username = '';
			$toJson[0]->idUser = '';
			$toJson[0]->msg = $my_access->the_msg;
			$toJson[0]->redirect = $my_access->login_page;
		}
		else 
		{
			$toJson[0]->Username = $my_access->user;
			$toJson[0]->idUser = $my_access->id;
			$toJson[0]->msg = $my_access->the_msg;
			$toJson[0]->redirect = $my_access->main_page;
		}
		echo json_encode($toJson);
		
	break;
	case 'logOut':
		
		$my_access = new Access_user();
		$toJson[0]->redirect = $my_access->log_out();
		echo json_encode($toJson);
		
	break;
			
	
	
}





?>
